package com.wk.net.connector;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 方法类。建立Socket服务端，接受客户端的连接，支持“调用-返回”式通信
 * 
 * @author Bai Yu
 *
 */
public class SocketServer {
	public SocketServer(int listenPort) {
		this.port = listenPort;
	}

	public void listen() throws IOException {
		listener = new ServerSocket(port);
	}

	public AcceptedClient accept() throws IOException {
		Socket client = listener.accept();
		return new AcceptedClient(client);
	}

	public void close() {
		try {
			listener.close();
		} catch (IOException e) {
		}
	}

	private ServerSocket listener;

	private int port;
}
